<?php

namespace App\Models;


use App\Libs\DataFormat;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;


class GoodsBanner extends Model
{

    use DataFormat;
    protected $table = 'goods_banner';


    public static $statusConf = ['0' => '关闭', '1' => '开启'];
    public static $jump_mode = [0 => '不跳转', 1 => '项目', '2' => '频道',];
    public static $formatKey = ['id' => 'int', 'title' => 'string', 'photo' => 'image_url', 'jump_mode' => 'int', 'jump_id' => 'int', 'href' => 'string'];


    public static function orgBanner($orgId)
    {
        $nodes = GoodsBanner::where('status', 1)->where('org_id', $orgId);

        //删除时间限制 后台不支持
//        $nodes = $nodes->where('start', '<=', date('Y-m-d'))->where('end', '>=', date('Y-m-d'));

        $nodes = $nodes->orderby('sort', 'asc')->orderBy('id', 'desc');
        $nodes = $nodes->get();

        $list = [];
        foreach ($nodes as $node) {
            $data = GoodsBanner::format($node);

            $list[] = $data;
        }
        return $list;
    }
}
